package com.wonders.frame.autoGeneration.support.enums;

import com.wonders.frame.common.Constant;

public enum ColumnTypeEnum {
    VARCHAR(
            "String",
            JsxElementEnum.INPUT,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "'\n" +
                    "            },"
    ),
    VARCHAR2(
            "String",
            JsxElementEnum.INPUT,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "'\n" +
                    "            },"
    ),
    NVARCHAR2(
            "String",
            JsxElementEnum.INPUT,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "'\n" +
                    "            },"
    ),
    DATE(
            "Date",
            JsxElementEnum.DATE,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "                render: (text, record) => {\n" +
                    "                    if (record." + Constant.ELEMENT_PLACEHOLDER2 + ") {\n" +
                    "                        return <span>{moment(record." + Constant.ELEMENT_PLACEHOLDER2 + ").format(Constants.DATE_FORMAT)}</span>\n" +
                    "                    }\n" +
                    "                    return '暂无'\n" +
                    "                },\n" +
                    "            },"
    ),
    DATETIME(
            "Date",
            JsxElementEnum.DATETIME,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "                render: (text, record) => {\n" +
                    "                    if (record." + Constant.ELEMENT_PLACEHOLDER2 + ") {\n" +
                    "                        return <span>{moment(record." + Constant.ELEMENT_PLACEHOLDER2 + ").format(Constants.DATE_TIME_FORMAT)}</span>\n" +
                    "                    }\n" +
                    "                    return '暂无'\n" +
                    "                },\n" +
                    "            },"
    ),
    TIMESTAMP(
            "Date",
            JsxElementEnum.DATETIME,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "                render: (text, record) => {\n" +
                    "                    if (record." + Constant.ELEMENT_PLACEHOLDER2 + ") {\n" +
                    "                        return <span>{moment(record." + Constant.ELEMENT_PLACEHOLDER2 + ").format(Constants.DATE_TIME_FORMAT)}</span>\n" +
                    "                    }\n" +
                    "                    return '暂无'\n" +
                    "                },\n" +
                    "            },"
    ),
    INT(
            "Integer",
            JsxElementEnum.INPUT_NUM,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "            },"
    ),
    NUMBER(
            "Integer",
            JsxElementEnum.INPUT_NUM,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "            },"
    ),
    TINYINT(
            "Integer",
            JsxElementEnum.INPUT_NUM,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "            },"
    ),
    DOUBLE(
            "Double",
            JsxElementEnum.INPUT,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "            },"
    ),

    LONG(
            "Long",
            JsxElementEnum.INPUT_NUM,
            "            {\n" +
                    "                title: '" + Constant.ELEMENT_PLACEHOLDER1 + "',\n" +
                    "                dataIndex: '" + Constant.ELEMENT_PLACEHOLDER2 + "',\n" +
                    "            },"
    ),

    ;

    private JsxElementEnum element;
    private String columnJs;
    private String javaType;

    ColumnTypeEnum(String javaType, JsxElementEnum element, String columnJs){
        this.javaType = javaType;
        this.element = element;
        this.columnJs = columnJs;
    }

    public JsxElementEnum getElement(){
        return element;
    }

    public String getJs(String p1, String p2){
        String columnJs = this.columnJs
                .replaceAll(Constant.ELEMENT_PLACEHOLDER1, p1)
                .replaceAll(Constant.ELEMENT_PLACEHOLDER2, p2);
        return columnJs;
    }
    public String getJavaType(){
        return this.javaType;
    }

}
